package com.lingyun.ucm.client.config.listener;

import com.lingyun.ucm.common.util.Constant;

import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

import java.rmi.Naming;
import java.rmi.registry.LocateRegistry;
/**
 * 
 * @author Terrence2013
 * 2018年1月24日 上午9:41:45
 * 项目启动初始化注册RMI服务, 需在web.xml中注册
 */
public class RMIClientStartupListener implements ServletContextListener {
    @Override
    public void contextInitialized(ServletContextEvent servletContextEvent) {
        try {
        	//启动rmi注册表
            LocateRegistry.createRegistry(Constant.CLIENT_RMI_PORT);
            //注册客户端RMI
            Naming.rebind(Constant.CLIENT_RMI_SERVICE, new RMIClientServiceImpl());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    @Override
    public void contextDestroyed(ServletContextEvent servletContextEvent) {
    	
    }

}
